﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DiceGame
{
    /// <summary>
    /// Define Properties and method of dice object
    /// </summary>
    public class Dice
    {
        #region Contructor
        /// <summary>
        /// Contructor with full params
        /// </summary>
        /// <param name="faces">list faces of dice</param>
        /// <param name="favoredFace">the favored face</param>
        /// <param name="proportionApply">the proportion factor apply</param>
        public Dice(string name,int favoredFace, int proportionApply)
        {
            this.Name = name;
            this.FavoredFace = favoredFace;
            this.ProportionApply = proportionApply;
            GetProportionFaces();
        }
        #endregion

        #region Methods
        public int RollingDice()
        {
            return faces.ChooseByRandom();
        }

        private void GetProportionFaces()
        {
            double defaultProportion = ((double)(100 / ( 5 + ProportionApply))) / 100;
            faces = new List<ProportionValue<int>>()
            {
                new ProportionValue<int>{ Value = 1, Proportion= (FavoredFace == 1) ? ProportionApply * defaultProportion : defaultProportion },
                new ProportionValue<int>{ Value = 2, Proportion= (FavoredFace == 2) ? ProportionApply * defaultProportion : defaultProportion},
                new ProportionValue<int>{ Value = 3, Proportion= (FavoredFace == 3) ? ProportionApply * defaultProportion : defaultProportion},
                new ProportionValue<int>{ Value = 4, Proportion= (FavoredFace == 4) ? ProportionApply * defaultProportion : defaultProportion},
                new ProportionValue<int>{ Value = 5, Proportion= (FavoredFace == 5) ? ProportionApply * defaultProportion : defaultProportion},
                new ProportionValue<int>{ Value = 6, Proportion= (FavoredFace == 6) ? ProportionApply * defaultProportion : defaultProportion},
            }.OrderByDescending(p => p.Proportion).ToList();
        }
        #endregion

        #region Properties and Field

        private List<ProportionValue<int>> faces { get; set; }
        public int FavoredFace { get; set; }
        public int ProportionApply { get; set; }
        public string Name { get; set; }
        #endregion
    }
}
